package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"group-card/common/constant"
	"group-card/model/entity"
	"group-card/rpc/card/cardclient"
	"group-card/rpc/card/internal/svc"
)

type SkinFindOneLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSkinFindOneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SkinFindOneLogic {
	return &SkinFindOneLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SkinFindOneLogic) SkinFindOne(in *cardclient.SkinFindOneRequest) (*cardclient.SkinFindOneResponse, error) {
	var ctx context.Context
	data, err := l.svcCtx.SkinModel.FindOne(ctx, &entity.CardSkinReq{
		Id: in.Id,
	})
	if err != nil {
		return nil, err
	}

	skin := &cardclient.SkinFindOneResponse{
		Id:         data.Id,
		Name:       data.Name,
		FaceValue:  data.FaceValue,
		Colour:     data.Colour,
		CustomerId: data.CustomerId,
		Type:       data.Type,
		Status:     data.Status,
		Image:      data.Image,
		AdminId:    data.AdminId,
		CreateAt:   data.CreateAt.Format(constant.YMDHIS),
		UpdateAt:   data.UpdateAt.Format(constant.YMDHIS),
		DeleteAt:   data.DeleteAt.Format(constant.YMDHIS),
	}

	return skin, nil
}
